package com.rd.student.ruanjian.class3.gaochenxi.day0801;

public class Test {

   public static void main(String[] args) {
      int[] arr = {60, 77, 33, 55, 11, 22, 80};
      Func();
      System.out.println("该数组最大值为:"+getMax(arr));
      System.out.println("该数组最大值为:"+getMax2(arr));
      System.out.println("该数组最大值为:"+getMax3(arr));
   }

   //NumberOne
   public static void Func() {
      int sum1 = 0;
      int sum2 = 0;
      outer:
      for (int i = 1; i <= 100; i++) {
         if (i % 7 == 0) {
            sum1 += i;
            sum2 += i;
            continue outer;
         }
         sum2 += i;
      }
      System.out.println("能被7整除的数的和为:"+sum1 + "\n总和为:" + sum2);
   }


   //NumberTwo
   //方法1
   public static int getMax(int[] arr){
      for(int i=0;i< arr.length;i++){
         for(int j=i;j>0;j--){
            if(arr[j]>arr[j-1]){
               break;
            }
            int temp=arr[j];
            arr[j]=arr[j-1];
            arr[j-1]=temp;
         }
      }
      return arr[arr.length-1];
   }

   //方法2
   public static int getMax2(int[] arr){
      int max=Integer.MIN_VALUE;
      for(int i=0;i<arr.length;i++){
         if(arr[i]>max){
            max=i;
         }
      }
      return arr[max];
   }

   //方法3
   public static int getMax3(int[] arr){
      for (int i = 0; i < arr.length - 1; i++) {
         for (int j = arr.length - 1; j > i; j--) {
            //一轮排序结束
            if (arr[i] > arr[j]) {
               int temp = arr[i];
               arr[i] = arr[j];
               arr[j] = temp;
            }
         }
      }
      return arr[arr.length-1];
   }
}


